package manager.modulo.financeiro;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.LinkedList;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.table.TableRowSorter;
import manager.auxiliares.AutoComplete;
import manager.auxiliares.Icons;
import manager.auxiliares.MensagemExcessao;
import manager.helpers.table.TableRowComparator;
import manager.interfaces.InterfaceRegister;
import manager.modulo.financeiro.dao.EntryTypeDao;
import manager.modulo.financeiro.dao.FinancialCategoryDao;

/**
 *
 * @author Thiago
 */
public class RegistroEntradaFinanceira implements InterfaceRegister {

    private JanelaEntradaFinanceiro financialEntryWindow;

    public LinkedList buscaAutoCompletar(String option, String search) {
        LinkedList<String> result = new LinkedList<String>();
        try {
            result = new FinancialCategoryDao().buscar(option, search, true);
        } catch (SQLException ex) {
            MensagemExcessao.mostrarMensagem(ex, "Auto Completar de Lançamentos");
        }
        return result;
    }

    public LinkedList buscaTabela(String option, String search) {
        LinkedList result = new LinkedList();
        try {
            result = FinancialCategoryDao.searchTable(option, search);
        } catch (SQLException ex) {
            MensagemExcessao.mostrarMensagem(ex, "Buscando Lançamentos");
        }
        return result;
    }

    public String getTituloEntidade() {
        return "Lançamentos";
    }

    public LinkedList<String> getOpcoesBusca() {
        LinkedList<String> searchOption = new LinkedList<String>();
        searchOption.add("Tipo de Lançamento");
        searchOption.add("Subscategorias");
        searchOption.add("Categoria");
        searchOption.add("Parceiro");
        return searchOption;
    }

    public void changeOptionSearch(AutoComplete autoComplete, String option, JComboBox jComboBoxValue) {
        if (option.equalsIgnoreCase("Tipo de Lançamento")) {
            autoComplete.setSearchWord("");
            if (jComboBoxValue.getItemCount() > 0) {
                jComboBoxValue.removeAllItems();
            }
            LinkedList<String> entryTypes = EntryTypeDao.getListEntryTypes();
            for (int i = 0; i < entryTypes.size(); i++) {
                jComboBoxValue.addItem(entryTypes.get(i));
            }
            autoComplete.getjTextField().setVisible(false);
            jComboBoxValue.setVisible(true);
        } else {
            autoComplete.getjTextField().setVisible(true);
            jComboBoxValue.setVisible(false);
        }
    }

    public LinkedList<String> getNomeColunaTabela() {
        LinkedList<String> columnNames = new LinkedList<String>();
        columnNames.add("");
        columnNames.add("Tipo de Lançamento");
        columnNames.add("Subcategoria");
        columnNames.add("Parceiro");
        columnNames.add("Valor");
        columnNames.add("Data");
        columnNames.add("");
        return columnNames;
    }

    public void inserirEntidade() {
        if (financialEntryWindow != null) {
            financialEntryWindow.dispose();
        }
        financialEntryWindow = new JanelaEntradaFinanceiro(0);
    }

    public void editarEntidade(int id) {
        if (financialEntryWindow != null) {
            financialEntryWindow.dispose();
        }
        financialEntryWindow = new JanelaEntradaFinanceiro(id);
    }

    public TableRowSorter getTableSorter() {
        TableRowComparator tableRowComparator = new TableRowComparator();
        return tableRowComparator;
    }

    public String getTituloBuscaPadrao() {
        return "Categoria";
    }

    public boolean isAdd() {
        return true;
    }

    public boolean isEdit() {
        return true;
    }

    public boolean isRemove() {
        return false;
    }

    public boolean isFiles() {
        return false;
    }

    public boolean isExport() {
        return true;
    }

    public boolean isPrint() {
        return false;
    }

    public ImageIcon getModuleIcon() {
        return new Icons().getFinancialModule();
    }

    public int getColumnCount() {
        return 4;
    }

    public void imprimir(int id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean isFilter() {
        return false;
    }

    public void filtro() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean temFiltroHabilitado() {
        return false;
    }

    public HashMap<String, Object> getFiltros() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
